import { DbConfig } from "../../src/config/DbConfig";
import { DaoBase } from "../../src/engine/dao/DaoBase";
import { MysqlClient } from "../../src/engine/utils/MySqlClient";
import { MysqlManager } from "../../src/engine/utils/MysqlManager";

export class LogGemDao extends DaoBase {

    public static DB_NAME: string = DbConfig.Db_Name.db_admin;

    public static async add_user_gems_log(userid: number, gems: number, operator: string, time: string, reseason: string) {
        let client: MysqlClient = await MysqlManager.instance.getDb(this.DB_NAME);
        let sql: string = `INSERT INTO t_log_gem(userid, gems,operator,time, reseason) VALUES(?,?,?,?,?) ;`
        let sqlParams = [userid, gems, operator, time, reseason];
        let results = await client.queryPromise(sql, sqlParams);
        if (results && results["affectedRows"] > 0) {
            return true
        }
        else {
            return false
        }
    }

    public static async get_log_gem(startTimeStr: string, endTimeStr: string) {
        let client: MysqlClient = await MysqlManager.instance.getDb(this.DB_NAME);
        let sql: string = "select * from t_log_gem WHERE time >= ? and time <= ?  ";
        sql += " order by time desc "
        let sqlParams = [startTimeStr, endTimeStr];
        let results = await client.queryPromise(sql, sqlParams);
        return results
    }

}